package com.ruoyi.web.controller.books;

import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.books.domain.BookManage;
import com.ruoyi.books.service.IBookManageService;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.uuid.UUIDUtils;
import com.ruoyi.system.service.ISysDictDataService;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图书信息Controller
 *
 * @author wt
 * @date 2025-03-15
 */
@RestController
@RequestMapping("/books/manage")
public class BookManageController extends BaseController
{
    @Autowired
    private IBookManageService bookManageService;
    @Autowired
    private ISysDictDataService iSysDictDataService;

    /**
     * 查询图书信息列表
     */
    @PreAuthorize("@ss.hasPermi('books:manage:list')")
    @GetMapping("/list")
    public TableDataInfo list(BookManage bookManage)
    {
        startPage();
        List<BookManage> list = bookManageService.selectBookManageList(bookManage);
        return getDataTable(list);
    }

    /**
     * 导出图书信息列表
     */
    @PreAuthorize("@ss.hasPermi('books:manage:export')")
    @Log(title = "图书信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BookManage bookManage)
    {
        List<BookManage> list = bookManageService.selectBookManageList(bookManage);
        ExcelUtil<BookManage> util = new ExcelUtil<BookManage>(BookManage.class);
        util.exportExcel(response, list, "图书信息数据");
    }

    /**
     * 获取图书信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('books:manage:query')")
    @GetMapping( value = "/{id}")
    public AjaxResult getInfo(@PathVariable String id)
    {
        System.out.println(id);
        return success(bookManageService.selectBookManageById(id));
    }

    /**
     * 新增图书信息
     */
    @PreAuthorize("@ss.hasPermi('books:manage:add')")
    @Log(title = "图书信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BookManage bookManage)
    {
        bookManage.setId(UUIDUtils.uuid());
        return toAjax(bookManageService.insertBookManage(bookManage));
    }

    /**
     * 修改图书信息
     */
    @PreAuthorize("@ss.hasPermi('books:manage:edit')")
    @Log(title = "图书信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BookManage bookManage)
    {
        return toAjax(bookManageService.updateBookManage(bookManage));
    }

    /**
     * 删除图书信息
     */
    @PreAuthorize("@ss.hasPermi('books:manage:remove')")
    @Log(title = "图书信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(bookManageService.deleteBookManageByIds(ids));
    }
    
    @PreAuthorize("@ss.hasPermi('books:manage:list')")
    @GetMapping("/getBookTypes/{type}")
    public TableDataInfo getBookTypes(@PathVariable String type){
        SysDictData dictData = new SysDictData();
        dictData.setDictType(type);
        return getDataTable(iSysDictDataService.selectDictDataList(dictData));
    }
}
